<?php

require_once("config.php");

class CMySQL {
	private static $instance=null;
	private $db;

	public static function getInstance() {
		if(self::$instance == null) {
			self::$instance=new CMySQl();
		}
		return self::$instance;
	}
	
	public function getDbNameFromDossier($dossier) {
		$sql="SHOW DATABASES";
		
		$result=mysql_query($sql, $this->db);
		while($row = mysql_fetch_assoc($result)) {
			if(md5($row["Database"]) == $dossier) {
				return $row["Database"];
			}
		}
		
		return false;
	}
	
	public function selectDb($dbName) {
		mysql_select_db($dbName, $this->db);
	}
	
	public function execQuery($sql) {
		return mysql_query($sql, $this->db);
	}

	private function __construct() {
		global $config;
		
		$this->db=mysql_connect($config["serveur"], $config["user"], $config["passWord"]);
	}
};

?>
